﻿
//退货操作
var columns =
            [
                 { display: 'Key', name: 'ID', type: 'text', hide: 1 },
                  { display: 'ReturnBillID', name: 'ReturnBillID', type: 'text', hide: 1 },
                 { display: 'StockID', name: 'StockID', type: 'text', hide: 1 },
                   { display: '产品类别', name: 'TypeName', mintWidth: 80, width: 120, type: 'text' },
                   { display: '产品名称', name: 'ProductName', mintWidth: 80, width: 160, type: 'text' },
                   { display: '产品编码', name: 'ProductCode', mintWidth: 80, width: 100, type: 'text' },
                    { display: '产品规格', name: 'ProductStandard', mintWidth: 80, width: 200, type: 'text' },
                { display: '退货数量', name: 'ReturnNo', mintWidth: 100, width: 140, type: 'int' },
                { display: '备注', name: 'Remarks', mintWidth: 80, width: 140 }
             ];

var manager;
//init controls
$(document).ready(function () {
    intiToobar();
    initligerGrid();
});

function initligerGrid() {
    manager = null;
    manager = $("#ReturnBillItemsGrid").ligerGrid({
        columns: columns,
      //  title: '退货细',//不能要标题，修改的BUG，不在ligerui.min.js文件中，所以这个BUG还是存在
        showTitle: false,
        width: '100%',
        enabledSort: true,
        enabledEdit: true,
        //height: '99%',
        minHeight:'100px',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
                                    { text: '退货明细' }
                                    ]
        },
         isChecked: f_isChecked, onCheckRow: f_onCheckRow, onCheckAllRow: f_onCheckAllRow,
         url: "../ReturnBill/GetJsonOfBillDetails?billId=" + $("#Id").val() + "&rand=" + Math.random()
    });
}

//收退货确认 
function audioOperation() {
    var billId = $("#Id").val();
    $.ligerDialog.confirm('是否确认？', function (yes) {
        if (yes) {
            if ($("#AffirmState").val() != "1") {
                $.get("../ReturnBill/Audit?billId=" + billId + "&orgCode=" + $("#HidOrgCode").val(), {}, function (data) {
                    if (data != undefined && data == "9") {
                        $.ligerDialog.success('确认成功!');
                        initligerGrid();
                        ajaxSubmitSuccess();
                    }
                });
            } else {
                $.ligerDialog.success('已确认过，不能重复确认!');
            }
        }
    });
}
//=========================================
function intiToobar() {
    $("#toptoolbar").ligerToolBar({ items: [
                { text: '退货信息管理',  icon: 'add' }
            ]
    });
}
//==============================

function f_onCheckAllRow(checked) {
    for (var rowid in this.records) {
        if (checked)
            addCheckedCustomer(this.records[rowid]['CustomerID']);
        else
            removeCheckedCustomer(this.records[rowid]['CustomerID']);
    }
}

/*
该例子实现 表单分页多选
即利用onCheckRow将选中的行记忆下来，并利用isChecked将记忆下来的行初始化选中
*/

var checkedCustomer = [];
function findCheckedCustomer(CustomerID) {
    for (var i = 0; i < checkedCustomer.length; i++) {
        if (checkedCustomer[i] == CustomerID) return i;
    }
    return -1;
}
function addCheckedCustomer(CustomerID) {
    if (findCheckedCustomer(CustomerID) == -1)
        checkedCustomer.push(CustomerID);
}
function removeCheckedCustomer(CustomerID) {
    var i = findCheckedCustomer(CustomerID);
    if (i == -1) return;
    checkedCustomer.splice(i, 1);
}
function f_isChecked(rowdata) {
    if (findCheckedCustomer(rowdata.CustomerID) == -1)
        return false;
    return true;
}
function f_onCheckRow(checked, data) {
    if (checked) addCheckedCustomer(data.ID);
    else removeCheckedCustomer(data.ID);
}
function f_getChecked() {
    alert(checkedCustomer.join(','));
}
